package com.bcbim.smart_water.road.service;

import com.bcbim.common.sys.Code;
import com.bcbim.smart_water.road.mapper.RoadMapper;
import com.bcbim.smart_water_interface.road.dao.RoadDAO;
import com.bcbim.smart_water_interface.road.dto.RoadDTO;
import com.bcbim.smart_water_interface.road.service.RoadService;
import com.bcbim.smart_water_interface.road.vo.RoadVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 道路维护service
 *
 * @author wxc
 * @version V 1.0.0
 * @date 2021/8/26
 **/
@Service(timeout = 60 * 1000, group = "road", version = "1.0.0")
public class RoadServiceImpl implements RoadService {
    @Autowired
    private RoadMapper roadMapper;

    /**
     * 添加道路
     *
     * @param roadDAO 道路数据库对应实体类
     * @return java.lang.Integer
     * @author wxc
     * @date 2021/8/26  10:50
     */
    @Override
    public Integer addRoad(RoadDAO roadDAO) {
        return roadMapper.addRoad(roadDAO);
    }


    /**
     * 获取道路列表数量
     *
     * @param roadDTO 道路列表查询实体类
     * @return java.lang.Integer
     * @author wxc
     * @date 2021/8/26  10:49
     */
    @Override
    public Integer getRoadListCount(RoadDTO roadDTO) {
        return roadMapper.getRoadListCount(roadDTO);
    }

    /**
     * 获取道路列表分页数据
     *
     * @param roadDTO 道路列表查询实体类
     * @return java.util.List<com.bcbim.pipeline_interface.road.vo.RoadVO>
     * @author wxc
     * @date 2021/8/26  10:49
     */
    @Override
    public List<RoadVO> getRoadList(RoadDTO roadDTO) {
        return roadMapper.getRoadList(roadDTO);
    }

    /**
     * 修改道路信息
     *
     * @param roadDAO 道路数据库对应实体类
     * @return java.lang.Integer
     * @author wxc
     * @date 2021/8/26  15:04
     */
    @Override
    public Integer updateRoad(RoadDAO roadDAO) {
        return roadMapper.updateRoad(roadDAO);
    }

    /**
     * 查看道路详情
     *
     * @param id 道路id
     * @return com.bcbim.pipeline_interface.road.vo.RoadVO
     * @author wxc
     * @date 2021/8/26  11:08
     */
    @Override
    public RoadVO getRoadDetail(String id) {
        return roadMapper.getRoadDetail(id);
    }

    /**
     * 逻辑删除道路
     *
     * @param requestDo 道路数据库对应实体类
     * @return java.lang.Integer
     * @author wxc
     * @date 2021/8/26  15:07
     */
    @Override
    public Integer deleteRoad(RoadDAO requestDo) {
        return roadMapper.updateRoad(requestDo);
    }

    /**
     * 判断道路名称是否已经存在
     *
     * @param roadDAO 道路数据库对应实体类
     * @return boolean  道路是否存在
     * @author wxc
     * @date 2021/9/6  9:27
     */
    @Override
    public boolean checkRoad(RoadDAO roadDAO) {
        return roadMapper.countRoadByName(roadDAO) > 0 ? true : false;
    }

    /**
     * 判断道路是否已经使用
     *
     * @param roadId 道路id
     * @return boolean
     * @author wxc
     * @date 2021/9/6  9:56
     */
    @Override
    public boolean checkRoadUse(String roadId) {
        String result = "";

        //管线
        result = roadMapper.checkRoadUse(roadId, "t_line");
        if (StringUtils.isNotEmpty(result)) {
            return true;
        }
        //管点
        result = roadMapper.checkRoadUse(roadId, "t_point");
        if (StringUtils.isNotEmpty(result)) {
            return true;
        }

        return false;
    }

    /**
     * 获取道路下拉列表
     *
     * @return java.util.List<com.bcbim.common.sys.Code>
     * @author wxc
     * @date 2021/9/13  13:46
     */
    @Override
    public List<Code> listRoadPull(String roadName) {
        return roadMapper.listRoadPull(roadName);
    }
}
